<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            FIS 发货
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">客户</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请选择/扫描客户" id="customerCode" value=""
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectCustomer()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">发货单号</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描/输入发货单号" id="consignment" value=""
                            onclick="getIdSelector();">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">车架号</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描车架号" id="cjnum" value="" onclick="getIdSelector();">
                    </div>
                </div>
            </li>
            <!-- <li class="aui-list-item" style="display:none">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">条码</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="tm">
                    </div>
                </div>
            </li>
            <li class="aui-list-item" style="display:none">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">条码ID</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="tmID">
                    </div>
                </div>
            </li> -->
            <!-- <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="mrlCode" disabled="true">
                    </div>
                </div>
            </li> -->
            <!-- <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">批次号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="lotCode" disabled="true">
                    </div>
                </div>
            </li> -->
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">转移数量</div>
                    <div class="aui-list-item-input">
                        <input type="number" id="qty" disabled="true">
                    </div>
                </div>
            </li>
            <!-- <div id="kuzhuan">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">目标库位</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请选择/扫描目标库位" id="relWorkCellCode" value=""
                                onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCell('2')"></i>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">来源库位</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请选择/扫描来源库位" id="workCellCode" value=""
                                onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCell('1')"></i>
                    </div>
                </li>
            </div> -->

            <div id="kuzhuan1">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">

                        <div class="aui-list-item-label">目标库位</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请选择/扫描仓库" id="relWorkCellCode" value=""
                                onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCellRel('2')"></i>
                    </div>
                </li>
            </div>
            <div id="chuku1">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">仓库</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="选择/扫描 仓库" id="workCenterCode" value=""
                                onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCenter()"></i>
                    </div>
                </li>
            </div>
            <div id="kuzhuan2">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">


                        <div class="aui-list-item-label">来源库位</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请选择/扫描库位" id="workCellCode" value=""
                                onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCellRel('1')"></i>
                    </div>
                </li>
            </div>

            <div id="chuku2">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">库位</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="选择/扫描 库位" id="workCellCodeCk" value=""
                                onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCell()"></i>
                    </div>
                </li>
            </div>

        </ul>
        <p></p>
        <p></p>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()">保存</div>
        <!-- <div style="background-color:white; height: 320px;width: 100%;margin-top:3%;border:solid 1px #D3D3D3;display:block" id="tableDiv">
        </div> -->
        <div style="background-color:white; height: 100%;width: 100%;padding-top: 1px;">
            <!-- <p id="countQty" style="font-size:0.9rem;color: #e51c23;padding-top: 4px;height: 1.5rem;"></p> -->
            <table class="table" style='width:100%;' id="tableS">
                <thead>
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                        <!-- <td algin='center' style="width:50px;">序号</td> -->
                        <td algin='center' style="width:150px;">车架号</td>
                        <!-- <td algin='center' style="width:120px;;">物料号</td> -->
                        <!-- <td algin='center' style="width:80px;">箱号</td> -->
                        <td algin='center' style="width:60px;">数量</td>
                        <td algin='center' style="width:80px;">操作结果</td>
                        <td algin='center' style="width:60px;">操作信息</td>
                    </tr>
                </thead>
                <tbody id="tbodyHtml">
                </tbody>
            </table>
        </div>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var customerGid = ""; //客户GID
    var customerCode = ""; //客户编码
    var customerName = ""; //客户名称
    var workCellGid = ""; //来源库位GID
    var workCellCode = ""; //来源库位编码
    var workCellName = ""; //来源库位名称
    var relWorkCellGid = ""; //目标库位GID
    var relWorkCellCode = ""; //目标库位编码
    var relWorkCellName = ""; //目标库位名称

    var workCenterGid = ""; //仓库GID
    var workCenterCode = ""; //仓库编码
    var workCenterName = ""; //仓库名称
    var workCellGidCk = ""; //库位GID
    var workCellCodeCk = ""; //库位编码
    var workCellNameCk = ""; //库位名称

    var scanRule = ""; //条码解析规则
    var relworkcell; //菜单路由参数
    var originworkcell; //菜单路由参数
    var businessType;
    var subBussinessType;
    var type;
    var workcell; //菜单路由参数
    var workcenter; //菜单路由参数

    var arrSave = [];//需要提交的箱信息

    //初始化查询仓库下拉框
    apiready = function () {

        //菜单参数
        var query = api.pageParam.query;
        relworkcell = query.relworkcell
        workcell = query.workcell
        workcenter = query.workcenter
        originworkcell = query.originworkcell
        businessType = query.businessType;
        subBussinessType = query.subBussinessType;
        type = query.type;
        console.log("目：" + relworkcell);
        console.log("源：" + originworkcell);
        console.log(businessType);
        console.log(subBussinessType);
        console.log(type);
        console.log(workcell);
        console.log(workcenter);


        if (type != undefined && type != null && type == "出库") {
            document.getElementById("kuzhuan1").style.display = "none";
            document.getElementById("kuzhuan2").style.display = "none";
            idSelector = "workCenterCode";
            //查询目标库位
            getWorkCenter(workcenter, idSelector);

            $("#workCenterCode").focus();
            idSelector = "workCenterCode";
        } else if (type != undefined && type != null && type == "库转") {
            document.getElementById("chuku1").style.display = "none";
            document.getElementById("chuku2").style.display = "none";
            idSelector = "relWorkCellCode";
            //查询目标库位O
            getWorkCellRel(relworkcell, idSelector, "2");
            idSelector = "workCellCode";
            //查询来源库位
            getWorkCellRel(originworkcell, idSelector, "1");
        } else {
            document.getElementById("chuku1").style.display = "none";
            document.getElementById("chuku2").style.display = "none";
            idSelector = "relWorkCellCode";
            //查询目标库位O
            getWorkCellRel(relworkcell, idSelector, "2");
            idSelector = "workCellCode";
            //查询来源库位
            getWorkCellRel(originworkcell, idSelector, "1");
        }



        $("#customerCode").focus();
        idSelector = "customerCode";

        //查询条码解析规则
        //       initScanRule();
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //查询扫描规则
    function initScanRule() {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem("un");
        var url = serverUrl + "/app/getTmScanRule";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    scanRule = myobj.scanRule
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {

            //1：来源库位
            if (idSelector == 'workCellCode') {

                $("#workCellCode").val(ret);
                //查询来源库位
                getWorkCellRel(ret, idSelector, "1");

                //24：目标库位
            } else if (idSelector == 'relWorkCellCode') {

                $("#relWorkCellCode").val(ret);
                //查询目标库位
                getWorkCellRel(ret, idSelector, "2");

                //5：扫描条码
            } else if (idSelector == 'cjnum') {
                $("#cjnum").val(ret);
                doSearch();
            } else if (idSelector == 'customerCode') {

                $("#customerCode").val(ret);
                //查询客户
                getCustomer(ret, idSelector);
            } else if (idSelector == 'consignment') {
                $("#consignment").val(ret);
            } else if (idSelector == 'workCenterCode') {

                $("#workCenterCode").val(ret);
                //查询仓库
                getWorkCenter(ret, idSelector);

                //2:库位
            } else if (idSelector == 'workCellCodeCk') {

                $("#workCellCodeCk").val(ret);
                //查询库位
                getWorkCell(ret, idSelector);

                //扫描条码
            }
        });
    }


    //1：仓库扫描校验
    function getWorkCenter(code, inputId) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCenter";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un,
                workCenterCode: code,
                mrlCode: "",
                lotCode: "",
                qty: ""
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    workCenterGid = list[0].workCenterGid;
                    workCenterCode = list[0].workCenterCode + ":" + list[0].workCenterName;
                    workCenterName = list[0].workCenterName;
                    console.log(workCenterGid);
                    document.getElementById(inputId).value = workCenterCode;
                    $("#workCellCodeCk").focus();
                    idSelector = "workCellCodeCk";
                    if (code == workcenter && workCellGidCk == "") {
                        getWorkCell(workcell, idSelector);
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#workCenterCode").focus();
                    $("#workCenterCode").select();
                }
            }
        });
    }

    //2：选择仓库
    function goSelectWorkCenter() {
        api.openWin({
            name: 'uwmSelectWorkCenter',
            url: 'uwmSelectWorkCenter.html',
            pageParam: {
                flag: "in",
                name: "uwmInterBankTransferFisFh",
                mrlCode: "",
                lotCode: "",
                qty: ""
            }
        });
    }

    //仓库选择后回调函数
    function setWorkCenter(id, code, name) {
        workCenterGid = id;
        workCenterCode = code;
        workCenterName = name;
        //$("#workCenterCode").attr("value",code+":"+name);
        document.getElementById('workCenterCode').value = code + ":" + name;
        $("#workCellCodeCk").focus();
        idSelector = "workCellCodeCk";
    }

    //3；PDA自带扫描回车事件
    $("#workCenterCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            //仓库编码
            $("#workCenterCode").val(sm);
            // console.log("扫描回车事件：" + sm);
            //校验改箱码是否存在
            getWorkCenter(sm, "workCenterCode");
        }
    });

    //5:库位扫描校验
    function getWorkCell(code, inputId) {
        //扫库位前先扫仓库
        if (inputId == "workCellCodeCk") {
            if (workCenterGid == "" || workCenterGid == null || workCenterGid == undefined) {
                api.toast({
                    msg: "请先选择/扫描 仓库",
                    duration: 3000
                });
                $("#workCellCodeCk").val("");
                workCellCodeCk = "";
                workCellGidCk = "";
                workCellNameCk = "";
                return;
            }
        }
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCell";
        var data = {
            values: {
                flag: "in_rk", //库内库间标识（out_kn库内  out_kj库间,in_rk入库出库）
                workCenterGid: workCenterGid, //仓库GID
                workCellCodeCk: code, //库位编码
                relWorkCellGid: "", //目标库位
                tm: "",
                workCellFlag: "", //原库位目标库位flag
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    workCellGidCk = list[0].workCellGid;
                    workCellCodeCk = list[0].workCellCode + ":" + list[0].workCellName;
                    workCellNameCk = list[0].workCellName;
                    document.getElementById(inputId).value = workCellCodeCk;
                    $("#boxnum").focus();
                    idSelector = "boxnum";

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#workCellCodeCk").focus();
                    $("#workCellCodeCk").select();
                }
            }
        });
    }

    //6：选择库位
    function goSelectWorkCell() {
        var tm = $("#tm").val();
        //仓库非空校验
        if (workCenterGid == "" || workCenterGid == null || workCenterGid == undefined) {
            api.toast({
                msg: "请先选择/扫描 仓库",
                duration: 3000
            });
            return;
        }

        api.openWin({
            name: 'uwmSelectWorkCell',
            url: 'uwmSelectWorkCell.html',
            pageParam: {
                flag: "in_rk",
                name: "uwmInterBankTransferFisFh",
                tm: tm,
                workCenterGid: workCenterGid,
                relWorkCellGid: "",
                workCellFlag: ""
            }
        });
    }

    //库位选择后回调函数
    function setWorkCell(id, code, name) {
        workCellGidCk = id;
        workCellCodeCk = code;
        workCellNameCk = name;
        document.getElementById('workCellCodeCk').value = code + ":" + name;
        $("#boxnum").focus();
        var e = "boxnum";
        idSelector = e;
    }

    //7；PDA自带扫描回车事件-库位
    $("#workCellCodeCk").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            //仓库编码
            $("#workCellCodeCk").val(sm);
            //校验改箱码是否存在
            getWorkCell(sm, "workCellCodeCk");
        }
    });



    //7:库位扫描校验
    function getWorkCellRel(code, inputId, flag) {
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCell";
        var data = {
            values: {
                flag: "out_kj", //库内库间标识（out_kn库内  out_kj库间,in_rk入库出库）
                workCenterGid: "", //仓库GID
                workCellCode: code, //库位编码
                relWorkCellGid: "", //目标库位
                tm: "",
                workCellFlag: "", //原库位目标库位flag
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    //源库位
                    if (flag == "1") {

                        workCellGid = list[0].workCellGid;
                        workCellCode = list[0].workCellCode + ":" + list[0].workCellName;
                        workCellName = list[0].workCellName;
                        document.getElementById(inputId).value = workCellCode;
                        $("#customerCode").focus();
                        idSelector = "customerCode";

                        //目标库位
                    } else if (flag == "2") {

                        relWorkCellGid = list[0].workCellGid;
                        relWorkCellCode = list[0].workCellCode + ":" + list[0].workCellName;
                        relWorkCellName = list[0].workCellName;
                        document.getElementById(inputId).value = relWorkCellCode;
                        $("#workCellCode").focus();
                        idSelector = "workCellCode";
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#" + inputId).focus();
                    $("#" + inputId).select();
                }
            }
        });
    }

    //8：选择库位
    function goSelectWorkCellRel(workCellFlag) {
        var tm = $("#tm").val();
        api.openWin({
            name: 'uwmSelectWorkCell',
            url: 'uwmSelectWorkCell.html',
            pageParam: {
                flag: "out_kj",
                name: "uwmInterBankTransferFisFh",
                tm: tm,
                workCenterGid: "",
                relWorkCellGid: relWorkCellGid,
                workCellFlag: workCellFlag
            }
        });
    }

    //库位选择后回调函数
    function setWorkCell(id, code, name, workCellFlag) {

        //源库位
        if (workCellFlag == "1") {

            workCellGid = id;
            workCellCode = code;
            workCellName = name;
            document.getElementById('workCellCode').value = code + ":" + name;

            //目标库位
        } else if (workCellFlag == "2") {

            relWorkCellGid = id;
            relWorkCellCode = code;
            relWorkCellName = name;
            document.getElementById('relWorkCellCode').value = code + ":" + name;
            $("#workCellCode").focus();
            var e = "workCellCode";
            idSelector = e;
        }
    }

    //9；PDA自带扫描回车事件-源库位
    $("#workCellCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            $("#workCellCode").val(sm);
            getWorkCellRel(sm, "workCellCode", "1");
        }
    });

    //10；PDA自带扫描回车事件-目标库位
    $("#relWorkCellCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            $("#relWorkCellCode").val(sm);
            getWorkCellRel(sm, "relWorkCellCode", "2");
        }
    });

    //11：选择客户
    function goSelectCustomer() {
        api.openWin({
            name: 'uwmSelectCustomer',
            url: 'uwmSelectCustomer.html',
            pageParam: {
                name: "uwmInterBankTransferFisFh",
            }
        });
    }

    //客户选择后回调函数
    function setCustomer(id, code, name) {
        customerGid = id;
        customerCode = code;
        customerName = name;
        //$("#workCenterCode").attr("value",code+":"+name);
        document.getElementById('customerCode').value = code + ":" + name;
        $("#customerCode").focus();
        idSelector = "customerCode";
    }

    //客户扫描校验
    function getCustomer(code, inputId) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getCustomer";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un,
                customerCode: code,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    customerGid = list[0].customerGid;
                    customerCode = list[0].customerCode + ":" + list[0].customerName;
                    customerName = list[0].customerName;
                    document.getElementById(inputId).value = customerCode;
                    $("#customerCode").focus();
                    idSelector = "customerCode";

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });

                    $("#customerCode").focus();
                    $("#customerCode").select();
                }
            }
        });
    }

    //保存按钮
    function save() {

        //发货单号
        var consignment = $("#consignment").val();

        //客户非空校验
        if (customerGid == "" || customerGid == null || customerGid == undefined) {
            api.toast({
                msg: '请选择/扫描客户',
                duration: 3000
            });
            return;
        }

        if (type != undefined && type != null && type == "出库") {

        } else {
            //目标库位非空校验
            if (relWorkCellGid == "" || relWorkCellGid == null || relWorkCellGid == undefined) {
                api.toast({
                    msg: '请选择/扫描 目标库位',
                    duration: 3000
                });
                return;
            }

            //源仓库和目标仓库不能一样
            if (workCellGid != null && workCellGid != "" && workCellGid == relWorkCellGid) {
                api.toast({
                    msg: '源库位和目标库位不能一样',
                    duration: 3000
                });
                return;
            }
        }


        api.showProgress({
            title: '保存中...',
        });
        console.log(workCellGidCk)
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/uwmInterBankTransferSaveFisFh";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                customerGid: customerGid, // 客户
                consignment: consignment, // 发货单号
                relWorkCellGid: relWorkCellGid, // 目标库位
                workCellGid: workCellGid, //源库位编码
                workCenterGid: workCenterGid, // 目标库位
                workCellGidCk: workCellGidCk, //源库位编码
                list: JSON.stringify(arrSave),
                businessType: businessType,
                subBussinessType: subBussinessType,
                type: type,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                console.log("返回来啦:" + data);
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    // api.toast({
                    //     msg: "保存成功",
                    //     duration: 3000
                    // }); //清空表单
                    arrSave = [];
                    $("#customerCode").val("");
                    $("#consignment").val("");
                    $("#tm").val("");
                    $("#tmID").val("");
                    $("#cjnum").val("");
                    $("#lotCode").val("");
                    $("#qty").val("");

                    //回显保存结果
                    console.log("list:" + JSON.stringify(myobj.list));
                    var list = myobj.list;
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;' >";
                        html += "<td name='cjnum'>" + list[i].cjnum + "</td>";
                        // html += "<td name='boxnum'>" + list[i].boxnum + "</td>";
                        html += "<td name='qty'>" + list[i].qty + "</td>";
                        if (list[i].resultCode == 'S') {
                            html += "<td name='resultCode' style='background-color:green;'>" + list[i].resultCode + "</td>";
                            html += "<td name='resultMsg' style='background-color:green;'>" + list[i].resultMsg + "</td>";
                        } else if (list[i].resultCode == 'E') {
                            html += "<td name='resultCode' style='background-color:red;'>" + list[i].resultCode + "</td>";
                            html += "<td name='resultMsg' style='background-color:red;'>" + list[i].resultMsg + "</td>";
                        }
                        html += "</tr>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);




                    $("#message").html(myobj.message);
                    $("#cjnum").focus();
                    idSelector = "cjnum";
                } else if (myobj.code == '1') {
                    $("#cjnum").val("");
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }






    //删除备货箱
    function delDetail(cjnum) {
        api.confirm({
            title: '提示',
            msg: "确认撤销箱号 【" + cjnum + "】物料？",
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                var newArr = [];
                for (var i = 0; i < arrSave.length; i++) {
                    if (cjnum != arrSave[i].cjnum) {
                        newArr.push(arrSave[i]);
                    }
                }
                arrSave = newArr;
                freshTable();
            }
        });
    }
    function freshTable() {
        var html = "";
        for (var i = 0; i < arrSave.length; i++) {
            html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;' onclick='delDetail(\"" + arrSave[i].cjnum + "\")'>";
            html += "<td name='cjnum'>" + arrSave[i].cjnum + "</td>";
            // html += "<td name='mrlCode'>" + arrSave[i].mrlCode + "</td>";
            // html += "<td name='boxnum'>" + arrSave[i].boxnum + "</td>";
            html += "<td name='qty'>" + arrSave[i].qty + "</td>";
            html += "</tr>";
        }

        $api.html($api.byId("tbodyHtml"), html);
    }


    //查询
    function doSearch() {
        //车序号
        var cjnum = $("#cjnum").val();

        //车序号不能为空
        if (cjnum == null || cjnum == "" || cjnum == undefined) {
            api.toast({
                msg: "请 录入/车架号",
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/fisfhSearch";
        var data = {
            values: {
                cjnum: cjnum,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    //                   $("#mrlCode").val(myobj.mrlCode);
                    $("#qty").val(myobj.qty);
                    var model = {
                        //                        mrlCode: myobj.mrlCode, //物料号
                        // boxnum: myobj.boxnum, //箱号
                        qty: myobj.qty, //转移数量
                        cjnum: cjnum, //箱号
                    }
                    arrSave.push(model);
                    freshTable();
                    //失败
                } else if (myobj.code == "1") {
                    $("#cjnum").val("");
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }





    //车架监听回车事件
    $("#cjnum").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            $("#tm").val(tm);
            doSearch();
        }
    });

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>